
package Lab6;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.rmi.*;


public class UrrunekoJaurtitzaileFrame extends JFrame {
  JPanel jPanel1 = new JPanel();
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  UrrunekoAurkezpena a = new UrrunekoAurkezpena();
  JTextArea jTextArea1 = new JTextArea();

  public static final String zerbitzuIzena = "sarreraSisteman";

  public UrrunekoJaurtitzaileFrame() {
    super();
    try  {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }


  private void jbInit() throws Exception {
    this.getContentPane().setLayout(null);
    this.setSize(new Dimension(400, 300));
    jPanel1.setLayout(null);
    jPanel1.setBounds(new Rectangle(0, 0, 392, 273));
    jLabel1.setText("Negozio logika duen hostIzena:portua :");
    jLabel1.setBounds(new Rectangle(52, 50, 279, 17));
    jTextField1.setText("localhost");
    jTextField1.setBounds(new Rectangle(52, 72, 268, 24));
    jButton1.setText("Aurkezpena egikaritu");
    jButton1.setBounds(new Rectangle(93, 116, 194, 34));
    jButton1.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    jButton2.setText("Negozioaren Logika esleitu");
    jButton2.setBounds(new Rectangle(94, 162, 194, 32));
    jTextArea1.setBounds(new Rectangle(46, 210, 308, 57));
    jButton2.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        jButton2_actionPerformed(e);
      }
    });
    this.setTitle("Aurkezpena jaurtitzeko eta Negozio Logika esleitzeko");
    this.getContentPane().add(jPanel1, null);
    jPanel1.add(jLabel1, null);
    jPanel1.add(jTextField1, null);
    jPanel1.add(jButton1, null);
    jPanel1.add(jButton2, null);
    jPanel1.add(jTextArea1, null);
  }

  void jButton1_actionPerformed(ActionEvent e) {
    a.setVisible(true);
  }

  void jButton2_actionPerformed(ActionEvent e) {
   try{
	   System.setProperty("java.security.policy", "client.policy");
		if(System.getSecurityManager()==null){
			System.setSecurityManager(new RMISecurityManager());
		}
    UrrunekoNegozioLogikaInterfazea urrunekoObj;

   String host = jTextField1.getText();
   String zerbIzena = "rmi://"+host+"/"+zerbitzuIzena;
   // 	"rmi://IP_Helbidea:PortuZenb/ZerbitzuarenIzena"

    urrunekoObj = (UrrunekoNegozioLogikaInterfazea)Naming.lookup(zerbIzena);
    a.setNegozioLogika(urrunekoObj);
    jTextArea1.setText("Negozio logika esleitua\n");
   }
   catch (Exception ex) {jTextArea1.setText("Errorea negozio logika esleitzean\n");
                         jTextArea1.append(ex.toString());}
  }
  
public static void main (String[] args){
	UrrunekoJaurtitzaileFrame  proba=new UrrunekoJaurtitzaileFrame();
	proba.setVisible(true);
	proba.setDefaultCloseOperation(EXIT_ON_CLOSE);
	
	
}
}


